# Kernel Makefile

C_SRC = main.c multiboot.c io.c gdt.c idt.c pic.c cpuid.c msr.c \
 lapic.c ioapic.c pci.c acpi_osl.c mp.c rtc.c pmm.c kmalloc.c devmgr.c \
 legacy.c pit.c paging.c process.c scheduler.c keyboard.c
C_OBJ = main.o multiboot.o io.o gdt.o idt.o pic.o cpuid.o msr.o \
 lapic.o ioapic.o pci.o acpi_osl.o mp.o rtc.o pmm.o kmalloc.o devmgr.o \
 legacy.o pit.o paging.o process.o scheduler.o keyboard.o

S_SRC = boot.S gdtasm.s isr.S
S_OBJ = boot.o gdtasm.o isr.o

OBJS = $(S_OBJ) $(C_OBJ) $(D_OBJ)

INCLUDES = -I./include -I../klibc/include -I../datastructs/include

LIBS = ../klibc/klibc.a ../acpi/acpi.a ../datastructs/datastructs.a
LIB_INCLUDE = -L../klibc

CC = gcc
CFLAGS = -fno-builtin -fno-pic -Wall -Wstrict-prototypes -nostdinc -nostartfiles -nodefaultlibs -m32 $(INCLUDES)

CPP = cpp
CPPFLAGS = -nostdinc $(INCLUDES)

AS = as
ASFLAGS = --32 $(INCLUDES)

LD = ld
LDFLAGS = -melf_i386 -T linker.ld

kernel.elf:	$(OBJS) $(LIBS)
	$(MAKE) klibc
	$(MAKE) datastructs
	$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o kernel.elf
	
klibc:
	cd ../klibc && $(MAKE)
	
datastructs:
	cd ../datastructs && $(MAKE)

.SUFFIXES:	.s .o .c .elf .S

.S.s:
	$(CPP) $(CPPFLAGS) $*.S -o $*.s
	
.S.o:
	$(CPP) $(CPPFLAGS) $*.S -o $*.s
	$(AS) $(ASFLAGS) -o $*.o $*.s
	
.s.o:	
	$(AS) $(ASFLAGS) -o $*.o $*.s

.c.s:
	$(CC) $(CFLAGS) -S $*.c
	
.c.o:
	$(CC) $(CFLAGS) -o $*.o -c $*.c
	
.o.elf:
	$(LD) $(LDFLAGS) -o $*.elf $*.o
	
clean:	
	rm *.o *.elf
	
install: kernel.elf
	cp kernel.elf ../../mnt/boot/kernel.elf 

install_mac: kernel.elf
	cp kernel.elf /Volumes/Untitled\ 1/BOOT/
